﻿using GKQC.Language;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

namespace GKQC
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。 
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                //设置应用程序处理异常方式：ThreadException处理
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                Application.Run(new LoginForm());
            }
            catch (Exception ex)
            {
                GKQC.Common.Logger.LogError(ex);
                Application.Run(new LoginForm());
            }

            void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                QMessageBox.ShowException(e.ExceptionObject as Exception);
            }

            void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
            {
                QMessageBox.ShowException(e.Exception);
            }
        }
    }
}
